package me.shiqiang.im.linsteners;

import com.aliyun.openservices.ons.api.Producer;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.annotation.OnEvent;
import com.fasterxml.jackson.core.JsonProcessingException;
import me.shiqiang.im.enums.MessageCmd;
import me.shiqiang.im.msg.SndMsg;
import me.shiqiang.im.server.ConnectionContext;
import me.shiqiang.im.utils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author cuishiqiang
 * @date 2017/12/14 下午3:10
 */
@Component("SndMsgListener")
public class SndMsgListener extends Listener{
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    StringRedisTemplate redisTemplate;

    @Autowired
    Producer producer;

    @Value("${server.id}")
    private String serverId;

    @Value("${com.tst.rocketmq.producer.topic}")
    private String topic;

    @OnEvent(MessageCmd.SND_MSG)
    public void onSndMsg(SocketIOClient client, SndMsg msg) throws JsonProcessingException {
        ConnectionContext.getInstance().nextProcessor().sendEvent(MessageCmd.SND_MSG,msg);
        logger.info(JsonUtils.getInstance().toJson(msg));
    }
}
